<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    // 实现函数的链式调用
    function Hero(name) {
      let o = {}
      o.name = name
      o.time = 0

      console.log("Hi,this is " + o.name);

      o.kill = function (bugs) {
        if (bugs === 1) {
          console.log("Kill " + (bugs) + " bugs");
        } else {
          console.log(11);
          setTimeout(() => {
            console.log("Kill " + (bugs) + " bugs");
          }, 1000 * this.time)
        }
        return o
      }

      o.recover = function (bloods) {
        console.log("恢复了" + bloods + "血");
        return o
      }
      o.sleep = function (sleepTime) {
        this.time = sleepTime
        return o
      }
      return o
    }

    // Hero('57er').kill(1)
    Hero('57er').sleep(2).kill(5)
  </script>
</body>

</html>